Skip to content

Fix Octokit's GitHub reads in the native-AOT build - #48

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/aot-octokit
Nov 12, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
fix/aot-octokit

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Fixes #47

The native-AOT binary (the per-RID packages, the container and the GitHub Action) now reads releases and issues the same way the managed builds do. Before, find-previous and generate printed nothing and current-version threw. A new ./build.sh smokeaot target runs the AOT binary against GitHub in CI's aot-pack job, so this cannot come back unnoticed.

Why

Octokit reads every response with SimpleJson (PocoJsonSerializerStrategy). SimpleJson uses reflection, and Octokit has no trimming annotations. The trimmed binary had lost three things that reflection needs:

  1. The models' constructors and setters. Rooting only the List<T> constructors still left this error:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object, Type) + 0x91c
       at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object, Type) + 0x768
    
  2. List<T>'s capacity constructor. SimpleJson makes each JSON array into a List<T> with MakeGenericType and finds List(int) by reflection. Nothing calls that constructor statically for Octokit's models, so the lookup returns null and invoking it throws. Rooting only the Octokit assembly still gave the NullReferenceException from the issue, at DeserializeObject + 0x6f8.

  3. StringEnum<T>(string) for each enum the models reach. StringEnum is a struct, so native AOT compiles each instantiation separately and an open-type entry does not cover it. With 1 and 2 fixed, every issue list still failed:

    System.MissingMethodException: No parameterless constructor defined for type 'Octokit.StringEnum`1[Octokit.ItemState]'.
       at System.ActivatorImplementation.CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[]) + 0x42c
       at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) + 0x9b8
    

    GithubScanner.GetClosedIssues swallows that exception, so generate printed empty notes. find-previous was empty for the same reason: HasLatestRelease swallows the exception from the first read.

I kept Octokit for the reads and did not replace them with HttpClient and source-generated JSON. GithubScanner, Labeler and GitHubItem are public, and their signatures take Octokit's GitHubClient and Issue. Replacing them would change public API, which is more than a bug fix should do.

What

  • release-notes.csproj roots the Octokit assembly (TrimmerRootAssembly), only for RID builds, alongside the existing AOT settings.
  • The new OctokitClient.Create builds the GitHubClient that ReleaseNotesRunner.Run used to build inline. Its DynamicDependency attributes keep List<>'s constructors and the constructors of the five StringEnum<T> instantiations that Release, Issue, Label and Branch reach through their properties: ItemState, ItemStateReason, LockReason, MergeableState and TeamPrivacy. I found these by walking the property graph of Octokit 14.0.0 with reflection. Because they are typeofs, the build breaks if Octokit removes one.
  • Cost: the osx-arm64 binary grows from 10.8 MB to 13.9 MB. Octokit's IL2104/IL3053 summary warnings remain. Rooting does not silence them. The detailed warnings (TrimmerSingleWarn=false) are the same IL2067/IL2070/IL2075 reflection warnings plus one IL3050 for MakeGenericType. Those calls now have what they need for the models this tool reads.
  • ./build.sh smokeaot publishes the AOT binary for the current machine. It then runs find-previous, current-version --query 1.11 and generate against elastic/apm-agent-dotnet 1.11.0, anonymously, and fails unless the known output comes back. It stops at the first failing command, so a broken binary spends few requests. A passing run spends about 15 of the 60 anonymous requests an hour.
  • ci.yml's aot-pack job runs ./build.sh smokeaot -s after the pack step, on each RID it builds. The job uses a bare -s, which Make.Fs 0.25 accepts.
  • AGENTS.md records the rule: a newly read Octokit model can need a new StringEnum<T> entry.

Verify

Local, macOS arm64, .NET SDK 11.0.100:

  • Reproduced on origin/main with dotnet publish -f net10.0 -r osx-arm64 and no token. current-version elastic apm-agent-dotnet --query 1.11 --version 1.11.0 threw the reported exception. find-previous printed an empty line. generate printed only the "View the full list" link.

  • The smoke target fails without the fix and passes with it:

    # origin/main
    release-notes find-previous:
    [make] Target 'smokeaot' failed: the native-AOT binary's find-previous did not print '1.10.0'
    
    # Octokit rooted and List<> kept, StringEnum<T> not yet kept
    release-notes generate:
    https://github.com/elastic/apm-agent-dotnet/compare/1.10.0...1.11.0
    ### [View the full list of issues and PRs](...)
    [make] Target 'smokeaot' failed: the native-AOT binary's generate did not print '- #1239 Add Cosmos DB support  (issue: #1154)'
    
    # this branch
    release-notes find-previous:
    1.10.0
    release-notes current-version:
    1.11.1
    1.11.2
    release-notes generate:
    https://github.com/elastic/apm-agent-dotnet/compare/1.10.0...1.11.0
    ## New Features
    - #1239 Add Cosmos DB support  (issue: #1154)
    - #1310 Implement config to ignore the sampled flag in traceparent
    ## Uncategorized
    - #1302 Prefer W3C traceparent over elastic-apm-traceparent
    

    This matches the managed net10.0 build's output on the same commands.

  • The AOT and managed builds agree on other data too. generate against nullean/release-notes (with a token, for three label sets) produced byte-identical output from both builds.

  • The binary that CI's own pack step builds (dotnet pack -c Release -r osx-arm64), taken out of the nupkg, gives correct find-previous and current-version output.

  • mise run ci passes: build, pack, validate and the API diff (0 breaking changes, no diff) all pass, and curb check reports 0 changes. mise run check, actionlint (with shellcheck) and zizmor .github report no findings.

Not verified:

  • The smoke step on the Linux and Windows runners. It runs there only in CI.
  • apply-labels and create-release in the AOT build. Their Octokit reads (Labels.Get, Branch.Get) are covered by the same entries (Label and Branch were in the property walk), but I did not run them, because they write to GitHub.
  • The smoke step runs anonymously. GitHub-hosted runners can share an IP, so a 403 rate-limit response is possible but unlikely.

🤖 Generated with Claude Code

Fixes #47. In the native-AOT binary, find-previous and generate printed
nothing and current-version threw a NullReferenceException in
PocoJsonSerializerStrategy.DeserializeObject. Octokit reads responses by
reflection with no trimming annotations, so the trimmed binary had lost
three things that reflection needs:

- the models' constructors and setters: the csproj now roots the Octokit
  assembly for RID builds;
- List<T>'s capacity constructor, which SimpleJson uses for every JSON
  array;
- the StringEnum<T>(string) constructor for each enum the read models
  reach (ItemState, ItemStateReason, LockReason, MergeableState,
  TeamPrivacy). StringEnum is a struct, so each instantiation needs its
  own entry.

OctokitClient creates the client and carries DynamicDependency entries
for the last two. The binary grows from 10.8 MB to 13.9 MB on osx-arm64.

./build.sh smokeaot publishes the AOT binary for this machine and runs
find-previous, current-version and generate against
elastic/apm-agent-dotnet 1.11.0, failing unless the known output comes
back. CI's aot-pack job runs it after packing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz Mpdreamz added the bug A defect fixed (patch) label Nov 12, 2026
@Mpdreamz
Mpdreamz merged commit 57451bd into main Nov 12, 2026
6 checks passed
@Mpdreamz
Mpdreamz deleted the fix/aot-octokit branch November 12, 2026 09:58
Mpdreamz added a commit that referenced this pull request Nov 12, 2026
This brings every dependency of release-notes to its latest stable
version, the tool manifest and GitHub Actions included.

**Prompt summary:** Bring every dependency, GitHub Actions included, to
its latest version, drop unused and sponsor-gated packages, and release
the nullean repositories in dependency order.

## What

| Package | Old | New |
|---|---|---|
| MinVer | 6.0.0 | 8.0.0 |
| Nullean.Argh | 0.18.0 | 0.28.0 |
| NuGet.Versioning | 6.13.1 | 8.0.0 (net10.0), 7.9.0 (net8.0) |
| Octokit | 14.0.0 | 14.0.0 (already latest) |
| FSharp.Core | 11.0.101 | 11.0.101 (already latest) |
| Nullean.Make.Fs | 0.25.0 | 0.28.0 |
| Proc / Proc.Fs (transitive, through Make.Fs) | 0.17.0 | 0.21.0 |
| tool minver-cli | 6.0.0 | 8.0.0 |
| tool nupkg-validator | 0.10.0 | 0.11.5 |
| tool assembly-differ | 0.16.0 | 0.18.2 |
| tool curb-cli | 0.14.0 | 0.14.1 |
| docker/login-action | v3.7.0 | v4.8.0 |
| nullean/.github release-drafter.yml, zizmor.yml | v1.3.0 | v1.5.0 |

The global.json SDK (11.0.100) is already the latest .NET 11 SDK. The
other actions were already on their latest versions.

**TFM ceiling:** NuGet.Versioning 8.0.0 targets only net10.0 and net472.
On net8.0 it restores the .NET Framework build (NU1701), so net8.0 stays
on 7.9.0, the last version with a net8.0 target, through a
TFM-conditioned `PackageVersion`.

**Tool manifest order:** minver-cli, the only classic tool, comes first.
assembly-differ, nupkg-validator and curb-cli are RID-specific and
follow it. That order avoids the .NET 11.0.100 tool-restore bug on a
cold cache.

**Removed:** nothing. Every package is used: Octokit and
NuGet.Versioning by the tool, MinVer for versioning, and FSharp.Core and
Nullean.Make.Fs by the build. There are no sponsor-gated packages,
direct or transitive.

**Code changes forced by bumps:**
- nupkg-validator 0.11 needs the `validate` subcommand
(`build/scripts/Program.fs`).
- Make.Fs 0.27+ makes `-s` a switch without a value, so `./build.sh
<target> -s true` becomes `-s` in `ci.yml` and `AGENTS.md`.
- assembly-differ 0.18 moves to a `diff` subcommand.
`generateapichanges` now runs `assembly-differ diff …`, and `-f
github-comment` is kept.

The CLI surface is unchanged under Argh 0.28.0: the same five commands
and the same flags (checked with `--help`).

**Breaking:** none. The tool package declares no dependencies, so
consumers are not pulled up, and both TFMs ship as before.

## Verify

- `mise run ci`: build, pack, `nupkg-validator validate` (signed with
96c599bbe3e70f5d) and the `assembly-differ diff` 0.18.2 report against
the published `release-notes.any`. All pass. curb check: 0 would change.
- `mise run check`: curb clean, and zizmor reports no findings.
`actionlint` (with shellcheck) is clean, and `zizmor --min-severity
medium .github` reports no findings.
- `NUGET_PACKAGES=$(mktemp -d) DOTNET_CLI_HOME=$(mktemp -d) dotnet tool
restore`: "Restore was successful".
- `check-package-readme.sh` passes on `release-notes` and
`release-notes.any`.
- The sponsor-package grep over `project.assets.json` prints nothing.
- `dotnet list package --outdated` lists only the documented
NuGet.Versioning ceiling on net8.0. build/scripts with
`--include-transitive`: no updates.
- `dotnet pack -r osx-arm64` (native AOT) succeeds. The only trim/AOT
warnings are Octokit's own IL2104/IL3053, as on `main`. The Mach-O arm64
binary runs `--help` and `--version`.
- `./build.sh smokeaot -s`, anonymous against GitHub, run once, with #48
merged in: `find-previous` prints `1.10.0`, `current-version` prints
`1.11.1`/`1.11.2`, and `generate` lists #1239, #1310 and #1302 under
their headings. Exit 0.
- Mutation check: setting `SignAssembly` to false makes `mise run ci`
fail in `validatepackages` ("NOT publicly signed with expected token").
After the revert it passes again. The repository has no tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A defect fixed (patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native AOT build: GitHub reads return nothing and current-version throws in Octokit

1 participant